home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 737 / prlabel / getafile.c < prev    next >
C/C++ Source or Header  |  1995-03-18  |  6KB  |  206 lines

  1. /***************************************************************************
  2.  
  3.    Program:    PrLabel
  4.    File:       Support.c
  5.    
  6.    Version:    V1.2
  7.    Date:       14.09.92
  8.    Function:   Generally useful support routines for PrLabel
  9.    
  10.    Copyright:  SciTech Software 1992
  11.    Author:     Andrew C. R. Martin
  12.    Address:    SciTech Software
  13.                23, Stag Leys,
  14.                Ashtead,
  15.                Surrey,
  16.                KT21 2TD.
  17.    Phone:      +44 (0372) 275775
  18.    EMail:      UUCP: cbmuk!cbmuka!scitec!amartin
  19.                JANET: andrew@uk.ac.ox.biop
  20.                
  21. ****************************************************************************
  22.  
  23.    This program is not in the public domain, but it may be freely copied
  24.    and distributed for no charge providing this header is included.
  25.    The code may be modified as required, but any modifications must be
  26.    documented so that the person responsible can be identified. If someone
  27.    else breaks this code, I don't want to be blamed for code that does not
  28.    work! The code may not be sold commercially without prior permission from
  29.    the author, although it may be given away free with commercial products,
  30.    providing it is made clear that this program is free and that the source
  31.    code is provided with the program.
  32.  
  33. ****************************************************************************
  34.  
  35.    Description:
  36.    ============
  37.    GetAFile()
  38.    This routine attempts to open and use the asl library and V2.0 file
  39.    requester.
  40.    If unavailable, it uses Charlie Heath's file requester.
  41.  
  42.  
  43.  
  44.    N.B. 
  45.    Must be linked with the Heath file requester from Fish Disk 41.
  46.  
  47.  
  48. ****************************************************************************
  49.  
  50.    Usage:
  51.    ======
  52.    GetAFile(AslBase,Wind,Scr,prompt,fname,fdir,fbuff)
  53.    
  54.    Inputs:  (struct Library *)AslBase  A pointer to the asl.library base from
  55.                                        OpenLibrary(). If NULL uses the Heath
  56.                                        file requester
  57.             (struct Window *) Wind     A pointer to the Window on which the 
  58.                                        requester is to open
  59.             (struct Screen *) Scr      A pointer to the Screen on which the
  60.                                        requester is to open
  61.             char              *prompt  A pointer to a prompt string
  62.    I/O:     char              *fname   A pointer to a default filename (or NULL).
  63.                                        The chosen filename will be returned here
  64.             char              *fdir    A pointer to a default directory (or NULL).
  65.                                        The chosen directory will be returned here
  66.    Output:  char              *fbuff   Returns a pointer to the complete path and
  67.          
  68.    Returns: int                        1 if a file was selected
  69.                                        0 if the CANCEL gadget was chosen
  70.  
  71. ****************************************************************************
  72.  
  73.    Revision History:
  74.    =================
  75.    V1.1     09.02.91
  76.    Now frees the file requester memory (oops!)
  77.    V1.2     25.09.91
  78.    Now correctly builds fbuff when no path specified.
  79.    V1.3     28.05.92
  80.    ANSIed and static'd
  81.  
  82. ***************************************************************************/
  83. #include <exec/types.h>
  84. #include <intuition/intuition.h>
  85. #include <libraries/dosextens.h>
  86. #include <string.h>
  87. #include <stdlib.h>
  88. #include <stdio.h>
  89. #include <exec/memory.h>
  90. #include <libraries/dos.h>
  91. #include <intuition/intuitionbase.h>
  92. #include <libraries/asl.h>
  93.  
  94. #ifdef LATTICE
  95. #include <clib/exec_protos.h>
  96. #include <clib/dos_protos.h>
  97. #include <clib/asl_protos.h>
  98.  
  99. /* #include "asl_pragmas.h" */
  100.  
  101. #ifdef STOP_C
  102. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  103. int chkabort(void) { return(0); }  /* really */
  104. #endif
  105.  
  106. #endif /* LATTICE */
  107.  
  108. /* for file requester */
  109. BOOL   AslRequestTags( APTR request, ULONG tags, ...);
  110.  
  111. /***************************************************************************/
  112. GetAFile(struct Library *AslBase,
  113.          struct Window  *Wind,
  114.          struct Screen  *Scr,
  115.          char           *prompt,
  116.          char           *fname,
  117.          char           *fdir,
  118.          char           *fbuff)
  119. {
  120.    struct FileRequester *freq = NULL;
  121.    
  122.    struct Process *OurTask;
  123.    struct Window  *old_pr_WindowPtr;
  124.    char   *p;
  125.    int    retval=1,
  126.           j,
  127.           ASL_Done = 0;
  128.  
  129.    /* If have asl.library, try requester */
  130.    if(AslBase)
  131.    {
  132.       ASL_Done = 1;
  133.  
  134.       /* Allocate the file requester */
  135.       if(!freq) freq = AllocAslRequest(ASL_FileRequest, NULL);
  136.  
  137.       if(freq)
  138.       {
  139.          if(AslRequestTags((APTR)freq,
  140.             ASL_Hail,prompt,
  141.             ASL_OKText,"Select",
  142.             ASL_Window, Wind,
  143.             ASL_Dir, fdir,
  144.             ASL_File, fname,
  145.             TAG_DONE ))
  146.          {
  147.             strcpy(fdir,freq->rf_Dir);
  148.             strcpy(fname,freq->rf_File);
  149.          }
  150.          else
  151.          {
  152.             retval=0;
  153.          }
  154.          FreeFileRequest(freq);
  155.       }
  156.       else
  157.       {
  158.          /* Failed to allocate file requester */
  159.          ASL_Done = 0;
  160.       }
  161.       
  162.    }
  163.    
  164.    if(!ASL_Done) /* Either no asl.library or couldn't allocate file requester */
  165.    {
  166.       OurTask = (struct Process *)FindTask(0L);
  167.       old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
  168.       OurTask->pr_WindowPtr = (APTR)Wind;
  169.  
  170.       if(!get_fname(Wind,Scr,prompt,fname,fdir))
  171.       {
  172.          retval=0;
  173.       }
  174.  
  175.       OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  176.    }
  177.       
  178.    if(retval)  /* We got a filename back from one of the file requesters */
  179.    {
  180.       /* Kill any trailing spaces from the path */
  181.       for(j=strlen(fdir)-1; fdir[j] == ' ' && j>=0; j--)
  182.          fdir[j] = '\0';
  183.  
  184.       p = stpcpy(fbuff,fdir);
  185.       if( strlen(fdir) && *(p-1) != ':')
  186.       {
  187.          *p = '/';
  188.          p++;
  189.       }
  190.       p = stpcpy(p,fname);
  191.    }
  192.  
  193.    return(retval);
  194. }
  195.  
  196. /***************************************************************************/
  197. static BOOL AslRequestTags(APTR  request,
  198.                            ULONG tags, ...)
  199. {
  200.    return(AslRequest(request, (struct TagItem *)&tags));
  201. }
  202.  
  203.  
  204.  
  205.  
  206.